package net.sf.rose.business.bean.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.rose.jdbc.service.Service;
import net.sf.rose.util.DataUtil;

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Default;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;

/**
 * @author fengjian
 * @since 2014-3-27
 */
@Default
@Root(name = "actionDefine")
public class ActionUnitDefineBean extends Action {

	/** class类名 */
	@Attribute(name = "classname")
	private String classname = null;

	/** 参数列表 */
	@ElementList(required = false)
	private List<FieldBean> fields = new ArrayList<FieldBean>();

	public String getClassname() {
		return classname;
	}

	public void setClassname(String classname) {
		this.classname = classname;
	}

	public List<FieldBean> getFields() {
		return fields;
	}

	public void setFields(List<FieldBean> fields) {
		this.fields = fields;
	}

	/**
	 * 执行自定义操作
	 * @param request 	- Http请求
	 * @param response  - Http返回
	 * @param service 	- 数据库连接服务类 
	 * @param map 		- 前台传过来的数据
	 * @param data		- 上下文返回的数据
	 */
	public void execute(HttpServletRequest request, HttpServletResponse response, 
			Service service, Map<String, Object> map, Map<String, Object> data){
		Map<String, Object> m = parseField(this.fields);
		map.putAll(m);
		data.putAll(m);
		Action bean = (Action) DataUtil.getInstance(this.getClassname());
		bean.execute(request, response, service, map, data);
	}
}
